package com.toe.admin.controller;

import com.toe.commodity.service.CommodityClassesService;
import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.commodity.CommodityClassesDTO;
import com.toe.pojo.entity.commodity.CommodityClasses;
import com.toe.pojo.vo.commodity.CommodityClassVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "付费课程模块")
@RequestMapping("/costClass")
public class CostClassController {
    @DubboReference
    private CommodityClassesService dubboCommodityClass;

    @ApiOperation(value = "上架付费课程")
    @PostMapping("/add")
    public JsonResult<Void> addCostClass(@RequestBody CommodityClasses commodityClasses) {
       dubboCommodityClass.addNewCommodityClass(commodityClasses);
       return JsonResult.ok();
    }

    @ApiOperation(value = "更新付费课程信息")
    @PostMapping("/update")
    public JsonResult<Void> updateCostClass(@RequestBody CommodityClassesDTO commodityClassesDTO) {
        dubboCommodityClass.updateCommodityClass(commodityClassesDTO);
        return JsonResult.ok();
    }

    @ApiOperation(value = "删除付费课程")
    @PostMapping("/delete/{id}")
    public JsonResult<Void> deleteCostClass(@PathVariable Long id) {
        dubboCommodityClass.deletedCommodityClass(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "根据id查询付费课程详细信息")
    @GetMapping("/query/{id}/{userId}")
    public JsonResult<CommodityClassVO> selectCostClassById(@PathVariable Long id,@PathVariable Long userId) {
        CommodityClassVO commodityClassVO = dubboCommodityClass.getCommodityClassById(id,userId);
        return JsonResult.ok(commodityClassVO);
    }

    @ApiOperation(value = "根据分类分页查询付费课程")
    @GetMapping("/page/{pageNum}/{pageSize}/{id}")
    public JsonResult<JsonPage<CommodityClassVO>> selectCostClassByTypeId(@PathVariable Integer pageNum,@PathVariable Integer pageSize,@PathVariable Long id) {
        JsonPage<CommodityClassVO> commodityClassVO = dubboCommodityClass.getCommodityClassByClassTypeId(pageNum,pageSize,id);
        return JsonResult.ok(commodityClassVO);
    }

}
